const adminSchema = require('./schema/adminSchema')

const adminModel = {}

adminModel.addAdministrator = (user) => {
  const data = new adminSchema({
    name: user.name,
    userPwd: user.pwd
  })
  return new Promise((resolve, reject) => {
    data.save((err, res) => {
      if(err) {
        reject(err)
      } else {
        resolve(res)
      }
    })
  })
}

adminModel.getOneUser = (account) => {
  return new Promise((resolve, reject) => {
    adminSchema.findOne({name: account}).exec((err, row) => {
      if (err) {
        reject(err)
      } else {
        resolve(row)
      }
    })
  })
}

module.exports = adminModel
